use migration::{DbErr, Migrator, MigratorTrait};
use sea_orm::{Database, DbConn};
const DATABASE_URL: &str = "postgres://postgres:admin@localhost:5432/postgres";

pub async fn establish_connection() -> Result<DbConn, DbErr> {
    let db = Database::connect(DATABASE_URL)
        .await
        .expect("连接数据库失败");
    Migrator::up(&db, None)
        .await
        .expect("迁移失败");

    Ok(db)
}